<?php

/**
 * 	calendar dropdown
 *	dropdown with internal linking to detail page 
 *
 *	@author			pieter van peteghem <pieter@onedotonly.be>
 * 	@copyright		Copyright (c) 2010, Tijs Verkoyen. All rights reserved.
 *	@copyright		Onedot Only <we@onedotonly.be>
 *	@date			30 august 2010
 * 	@license		BSD License
 */
 
 
class CalendarDropdown extends modTEXT {


	/**
	 *	constructor
	 *	@param		array
	 *	@return		array
	 */
	function __construct( $vars ) {
		
		$this->_addvars( $vars );
		$this->_ref();
	}
	
	
	/**
	 *	define output 
	 *	add css, javascript and define internal function
	 */
	function output() {
	
		if( $this->action )
			$nodes = $this->{ "filter_" . $this->action }();
		
		if ( $nodes ) {
			$this->addclass( $this->action );
			$result = implode( "\n", $nodes );
		}
	
		return $this->parse( $result ) . $this->render_js();
			
	}
	
	
	/** 
	 *	filter all types
	 */
	function filter_all() {
		global $DB;
		
		// get nodes
		$CAL = new CALENDAR();
		$nodes = $CAL->filter_nodes( date('Y-m-d'), (int) $this->vars->days, "cal.single", false, false, (int) $this->vars->limit );
		
		// define output	
		$res[] = '<ul id="event" name="event">';
		$res[] = '<li class="choose event"><span class="choose">' . $this->vars->str . '</span><span class="dropdown"></span></li>';
				
		foreach( $nodes as $node ) 
			$res[] = '<li class="event go"><a href="' . $node->uri() . '">' . date( 'd/m/Y', strtotime( $node->get( 'date' ))) . ' - ' . $node->loc->get( 'name' ) . '</a></li>';
		
		$res[] = '</ul>';
		
		return $res;
	
	}
}


 